package com.scujj.cs6.controller;

import com.scujj.cs6.annotation.AuthCheck;
import com.scujj.cs6.common.Result;
import com.scujj.cs6.model.vo.UserFanVo;
import com.scujj.cs6.model.vo.UserFollowVo;
import com.scujj.cs6.service.UserFollowService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "用户关注接口", description = "用户关注相关 API")
@RestController
@RequestMapping("/subscribe")
@Validated
public class UserFollowController {
    @Autowired
    private UserFollowService userFollowService;

    @Operation(summary = "关注用户")
    @PostMapping("/{id}")
    @AuthCheck
    @Parameter(name = "Authorization", description = "认证信息", required = true , in = ParameterIn.HEADER)
    @ApiResponse(
            responseCode = "200",
            description = "成功",
            content = @Content(
                    mediaType = "application/json",
                    schema = @Schema(implementation = Result.class)
            )
    )
    public Result<Void> followUser(@Parameter(name = "id", required = true, in = ParameterIn.PATH) @PathVariable Long id, HttpServletRequest request) {
        userFollowService.followUser(id, request);
        return Result.success();
    }


    //用户是否有关注的用户
    @Operation(summary = "用户是否有关注的用户")
    @GetMapping("/isFollow")
    @AuthCheck
    @Parameter(name = "Authorization", description = "认证信息", required = true , in = ParameterIn.HEADER)
    @ApiResponse(
            responseCode = "200",
            description = "成功",
            content = @Content(
                    mediaType = "application/json",
                    schema = @Schema(implementation = Boolean.class ,example = "true")
            )
    )
    public Result<Boolean> isFollow(HttpServletRequest request) {
        return Result.success(userFollowService.isFollow(request));
    }



    @Operation(summary = "取消关注")
    @DeleteMapping("/{id}")
    @AuthCheck
    @Parameter(name = "Authorization", description = "认证信息", required = true , in = ParameterIn.HEADER)
    @ApiResponse(
            responseCode = "200",
            description = "成功",
            content = @Content(
                    mediaType = "application/json",
                    schema = @Schema(implementation = Result.class)
            )
    )
    public Result<Void> cancelFollow(@Parameter(name = "id", required = true, in = ParameterIn.PATH) @PathVariable Long id, HttpServletRequest request) {
        userFollowService.cancelFollow(id, request);
        return Result.success();
    }

    @Operation(summary = "获取关注列表")
    @GetMapping("/follows")
    @AuthCheck
    @Parameter(name = "Authorization", description = "认证信息", required = true , in = ParameterIn.HEADER)
    @ApiResponse(
            responseCode = "200",
            description = "成功",
            content = @Content(
                    mediaType = "application/json",
                    array = @ArraySchema(schema = @Schema(implementation = UserFollowVo.class))
            )
    )
    public Result<List<UserFollowVo>> getFollowList(HttpServletRequest request) {
        return Result.success(userFollowService.getFollowList(request));
    }

    @Operation(summary = "获取粉丝列表")
    @GetMapping("/fans")
    @AuthCheck
    @Parameter(name = "Authorization", description = "认证信息", required = true , in = ParameterIn.HEADER)
    @ApiResponse(
            responseCode = "200",
            description = "成功",
            content = @Content(
                    mediaType = "application/json",
                    array = @ArraySchema(schema = @Schema(implementation = UserFanVo.class))
            )
    )
    public Result<List<UserFanVo>> getFollowerList(HttpServletRequest request) {
        return Result.success(userFollowService.getFansList(request));
    }

}